/**
 * JS全局变量定义,需要Jquery1.3+支持
 */
var hanyxp = hanyxp || {
	ver : {author : "hanxp", time : "2009-7-18", copyright : "hanyxp 2009"}
};
var $ = jQuery;
var DebugFlag = true;
var Debug = function(arr, ff) {
	if (!DebugFlag) return;
	if ((typeof window.console != "undefined") && ff) {console.log(arr); return; }
	var wrap = $("<div id='exlDebug'><div class='dragHander' style='cursor:pointer;'>Debug drag handle <span id='clearDebug'>clear</span></div><dl></dl></div>"), str = "", div;
	if ($("#exlDebug").size() < 1) wrap.appendTo("body");
	$(window).scroll(function(){$("#exlDebug").css({top : $.getPageScroll()[1] + 50});});// scrollTop;
	$("#exlDebug").bind("dragstart", function(event) {return $(event.target).is(".dragHander")})
        .bind("drag", function(event) {$(this).css(event.shiftKey ? {left : event.offsetX } : {top : event.offsetY });});
	div = $("#exlDebug dl");
	if (!arr) return;
	if (div.length < 1) return;
	$("#clearDebug").bind("click",function(){div.empty()});
	if (typeof(arr) == "object" && typeof(arr.sort) == "function" && typeof(arr.length) == "number") {
		$.each(arr, function(i, v) {str += "<dd>" + v + "</dd>\n";});
	} else {
		str += "<dd>" + arr.toString() + "</dd>";
	}
	div.append(str);
};
/**
 * 常用正则
 */
hanyxp.reg = {
	userName : /^\w{4,20}$/,
	password : /^[\w\~\!@#\$%\^\&\*\(\)\-=\+\\\"\|\,\<\.\>\/\?\;\:\[\{\]\}]{4,20}$/,
	password2 : /^[\w\~\!@#\$%\^\&\*\(\)\-=\+\\\"\|\,\<\.\>\/\?\;\:\[\{\]\}]{4,20}$/,
	checkcode : /^\w{4}$/,
	required10 : /.{10,}$/,
	skype : /^[a-zA-Z]+[a-z\.\,\-\_A-Z0-9]{5,32}$/,
	filePic : /^.*(\.[Jj][Pp][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|\.[Pp][Nn][Gg])$/,
	fileVoice : /^.*(([^\.][\.][wW][aA][vV])|([^\.][\.][mM][pP][3]))$/,
	br : /^[\s]+$/,
	num : /^[\d]+$/,
	floatNum : /^(\d*)((\.?)\d+)$/,
	email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
	phone : /^\d{5,16}$/,
	age : /^[1]?\d{1,2}$/,
	phonePerfix : /^\d{2,5}$/,
	identitycard : /^\d{15}(\d{2}[A-Za-z0-9])?$/
};
/**
 * 常用工具类
 */
hanyxp.util = {
	/**
	 * 取字符长度, asic英文1:1, 中文1个=2
	 */
	getStrLen : function(str) {
		var len;
		var i;
		len = 0;
		for (i = 0; i < str.length; i++) {
			if (str.charCodeAt(i) > 255)
				len += 2;
			else
				len++;
		}
		return len;
	},
	/**
	 * 密码强度
	 */
	getStrong : function(pwd) {
		if (pwd == "")
			return 0;
		var strongvalue = 0;
		var tmpchar = "", hasUpperCase = false, hasLowerCase = false, hasOther = false, hasNumber = false;
		var regU = /[A-Z]/;
		var regL = /[a-z]/;
		var regN = /[0-9]/;
		var regO = /[~\!@#\$%\^\&\*()_\+\|<>\?\:"';,.\[\]]/;
		hasUpperCase = regU.test(pwd);
		hasLowerCase = regL.test(pwd);
		hasNumber = regN.test(pwd);
		hasOther = regO.test(pwd);
		strongvalue = 0 + (hasNumber ? 1 : 0) + (hasUpperCase ? 1 : 0)
				+ (hasLowerCase ? 1 : 0) + (hasOther ? 1 : 0)
				+ (pwd.length > 6 ? 1 : 0) + (pwd.length > 10 ? 1 : 0);
		return strongvalue;
	},
	/**
	 * 加载flash
	 */
	createSWF : function(wrap,swfSrc,w,h,color){
	    var so = new SWFObject(swfSrc,'swfId', w||"85", h||"22", "9", color||"#ffffff") ;
	    so.addParam('scaleMode' ,'noScale') ;
	    so.addParam("allowFullScreen", "false");
	    so.addParam("loop", "false");
	    so.addParam("allowScriptAccess", "sameDomain");
	    so.addParam("wmode","transparent");
	    so.write(wrap);
	},
	ver : {
		author : "hanxp",
		time : "2009-7-18"
	}
};

$(document).ready(function() {
	$("a").bind("focus", function(){$(this).blur();});
	var objFacebox = $('a[rel*=facebox]');if(objFacebox.size()>0){objFacebox.facebox();};
});
